package com.vhall.component.controller.goods;

import com.vhall.component.controller.goods.facade.LiveGoodsFacade;
import com.vhall.component.entity.goods.goods.*;
import com.vhall.component.entity.goods.vo.GetGoodsInfoResponseVO;
import com.vhall.component.entity.goods.vo.GuoxinPrdApiBindReqVO;
import com.vhall.component.entity.page.vo.PageVO;
import com.vhall.component.framework.common.annotation.VhallComponent;
import com.vhall.component.plugin.common.annotation.VssTokenAuth;
import com.vhall.component.plugin.common.utils.BeanCopyUtil;
import com.vhall.component.service.goods.GoodsApiService;
import com.vhall.component.service.goods.GoodsConsoleService;
import com.vhall.component.service.goods.GoodsService;
import com.vhall.component.service.goods.LiveGoodsConsoleService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

/**
 * @author guoxin.wang
 * @date 2021-10-26 11:25
 */
@VhallComponent
public class LiveGoodsController implements LiveGoodsFacade {

    @Autowired
    private LiveGoodsConsoleService liveGoodsConsoleService;

    @Autowired
    private GoodsService goodsService;

    @Autowired
    private GoodsApiService goodsApiService;

    @Autowired
    private GoodsConsoleService goodsConsoleService;

    @Override
    @VssTokenAuth
    public GoodsPage<GoodsBindListRspVO> getBindList(GoodsBindListReqVO reqVO) {
        LiveGoodsConsoleBindListReqVO param = new LiveGoodsConsoleBindListReqVO();
        BeanUtils.copyProperties(reqVO, param);
        param.setDefault();
        GoodsPage<LiveGoodsConsoleBindListRspVO> bindList = liveGoodsConsoleService.getBindList(param);
        if (bindList.getTotal() == 0) {
            return new GoodsPage<>(param.getPage(), param.getPageSize(), 0, new ArrayList<>(), bindList.getGoodsSwitch());
        }

        List<GoodsBindListRspVO> records = BeanCopyUtil.batchCopy(bindList.getData(), GoodsBindListRspVO::new);

        return new GoodsPage<>(param.getPage(), param.getPageSize(), bindList.getTotal(), records, bindList.getGoodsSwitch());
    }

    @Override
    public PageVO<GetGoodsInfoResponseVO> getGuoxinPrdBindList(GuoxinPrdApiBindReqVO reqVO) {
        return liveGoodsConsoleService.getGuoxinPrdBindList(reqVO);
    }

    @Override
    @VssTokenAuth
    public Boolean pushScreen(GoodsApiSendMessageReqVO reqVO) {
        return goodsApiService.pushScreen(reqVO);
    }

    @VssTokenAuth
    @Override
    public Boolean guoxinPushScreen(GoodsPushScreenReqVO reqVO) {
        return goodsService.pushScreen(reqVO);
    }

    @Override
    @VssTokenAuth
    public Boolean cancelPushScreen(GoodsPushScreenReqVO reqVO) {
        return goodsApiService.cancelPushScreen(reqVO);
    }

    @Override
    @VssTokenAuth
    public Boolean setGoodsSwitch(GoodsApiSetGoodsSwitchReqVO reqVO) {
        return goodsApiService.setGoodsSwitch(reqVO);
    }

    @Override
    @VssTokenAuth
    public GoodsRspVO get(GoodsDetailReqVO reqVO) {
        return goodsConsoleService.get(reqVO);
    }
    @VssTokenAuth
    @Override
    public GetGoodsInfoResponseVO detail(GoodsDetailReqVO reqVO) {
        return goodsConsoleService.detail(reqVO);
    }

}
